package com.ruoyi.web.controller.Resource;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ResourceTask;
import com.ruoyi.system.service.IResourceTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 资源信息任务Controller
 * 
 * @author ruoyi
 * @date 2023-12-25
 */
@RestController
@RequestMapping("/Resource/manage")
public class ResourceTaskController extends BaseController
{
    @Autowired
    private IResourceTaskService resourceTaskService;

    /**
     * 查询资源信息任务列表
     */
//    @PreAuthorize("@ss.hasPermi('Resource:manage:list')")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(ResourceTask resourceTask)
    {
        startPage();
        List<ResourceTask> list = resourceTaskService.selectResourceTaskList(resourceTask);

        return getDataTable(list);
    }

    /**
     * 导出资源信息任务列表
     */
//    @PreAuthorize("@ss.hasPermi('Resource:manage:export')")
    @Anonymous
    @Log(title = "资源信息任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResourceTask resourceTask)
    {
        List<ResourceTask> list = resourceTaskService.selectResourceTaskList(resourceTask);
        ExcelUtil<ResourceTask> util = new ExcelUtil<ResourceTask>(ResourceTask.class);
        util.exportExcel(response, list, "资源信息任务数据");
    }

    /**
     * 获取资源信息任务详细信息
     */
//    @PreAuthorize("@ss.hasPermi('Resource:manage:query')")
    @Anonymous
    @GetMapping(value = "/{iId}")
    public AjaxResult getInfo(@PathVariable("iId") Long iId)
    {
        return success(resourceTaskService.selectResourceTaskByIId(iId));
    }

    /**
     * 新增资源信息任务
     */
//    @PreAuthorize("@ss.hasPermi('Resource:manage:add')")
    @Anonymous
    @Log(title = "资源信息任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResourceTask resourceTask)
    {
        return toAjax(resourceTaskService.insertResourceTask(resourceTask));
    }

    /**
     * 修改资源信息任务
     */
//    @PreAuthorize("@ss.hasPermi('Resource:manage:edit')")
    @Anonymous
    @Log(title = "资源信息任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResourceTask resourceTask)
    {
        return toAjax(resourceTaskService.updateResourceTask(resourceTask));
    }

    /**
     * 删除资源信息任务
     */
//    @PreAuthorize("@ss.hasPermi('Resource:manage:remove')")
    @Anonymous
    @Log(title = "资源信息任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{iIds}")
    public AjaxResult remove(@PathVariable Long[] iIds)
    {
        return toAjax(resourceTaskService.deleteResourceTaskByIIds(iIds));
    }
}
